﻿using System.Collections.Generic;
using Vra.DataAccess.Entities;

namespace Vra.DataAccess
{
	public class ArtistDao : CommonDao<Artist>, IArtistDao
	{
		public IList<Artist> SearchArtists(string Name, string Nation)
		{
			IList<Artist> artists = new List<Artist>();
			using (var conn = GetConnection())
			{
				conn.Open();
				using (var cmd = conn.CreateCommand())
				{
					cmd.CommandText =
						"SELECT ArtistID, Name, BirthYear, DeceaseYear, Artist.NatID FROM ARTIST JOIN Nation on Artist.NatID = Nation.NatID WHERE Name like @Name AND Value like @Nation";
					cmd.Parameters.AddWithValue("@Name", "%" + Name + "%");
					cmd.Parameters.AddWithValue("@Nation", "%" + Nation);
					using (var dataReader = cmd.ExecuteReader())
					{
						while (dataReader.Read())
						{
							artists.Add(LoadItem(dataReader));
						}
					}
				}
			}

			return artists;
		}
	}
}
